package Enum;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test {

    //枚举是私有的，不能进行反射（非常安全）
    public static void reflectPrivateConstructor() {
        try {
            Class<?> c1 = Class.forName("Enum.TestEnum");
            Constructor<?> constructor = c1.getDeclaredConstructor(String.class,int.class,double.class,String.class);

            constructor.setAccessible(true);

            TestEnum testEnum = (TestEnum) constructor.newInstance("123",3,99.9,"青色");

            System.out.println(testEnum);

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }


    public static void main(String[] args) {
        reflectPrivateConstructor();
    }
}
